package com.zuihai.app.mvp.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.blankj.utilcode.util.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.zuihai.app.R;
import com.zuihai.app.mvp.model.entity.SearchHistory;
import com.zuihai.app.mvp.ui.holder.BaseViewHolderWraper;

import org.litepal.crud.DataSupport;

import java.util.List;

/**
 * Created by Zc on 2017/4/28.
 */

public class SearchHistoryAdapter extends BaseQuickAdapter<SearchHistory, BaseViewHolderWraper> {

    public SearchHistoryAdapter(Context context, List<SearchHistory> infos) {
        super(R.layout.layout_item_search_history, infos);
    }

    @Override
    protected void convert(BaseViewHolderWraper helper, SearchHistory item) {
        helper.setText(R.id.tv_text, item.text);
        ImageView ivDelete=helper.getView(R.id.iv_delete);

        ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtils.e(item.text);
                DataSupport.deleteAll(SearchHistory.class, "text = ? ", item.text);
                LogUtils.e("helper.getAdapterPosition():"+helper.getAdapterPosition());
                getData().remove(helper.getAdapterPosition());
                notifyDataSetChanged();
            }
        });
    }
}
